package com.longge;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class AddMinimum {

    public int addMinimum(String word) {
        int n = word.length();
        int[] d = new int[n + 1];

        for (int i = 1; i < word.length(); i++) {
            d[i] = d[i - 1] + 2;

            if (i > 1 && word.charAt(i - 1) > word.charAt(i - 2)) {
                d[i] = d[i - 1] - 1;
            }
        }
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new InputStream() {
            @Override
            public int read() throws IOException {
                return 0;
            }
        });
        return d[n];


    }
}
